function result = compare(interval,flag)
A = 0;
B = 0;
C = 0;
f11 = interval(1);
f12 = interval(2);
f21 = interval(3);
f22 = interval(4);
if (f11<f21 & f12<f22) | (f11<=f21 & f12<f22) | (f11<f21 & f12 <= f22)
    A = A+1;
elseif (f11>f21 & f12>f22) | (f11>=f21 & f12>f22) | (f11>f21 & f12 >= f22)
    B = B+1;
else
    C = C+1;
end
m1 = (f11+f12)/2;
m2 = (f21+f22)/2;
w1 = f12 - f11;
w2 = f22 - f21;
if (m1<m2 & w1<w2) | (m1<=m2 & w1<w2) | (m1<m2 & w1 <= w2)  
    A = A+1;
elseif (m1>m2 & w1<w2) | (m1>=m2 & w1<w2) | (m1>m2 & w1 <= w2)
    B = B+1;
else
    C = C+1;
end
alfa = 0.5;
p = max([1-max([(f12-f21)/(w1+w2),0]),0]);
if p > alfa 
    A = A+1;
elseif p < 1 - alfa
    B = B+1;
else
    C = C+1;
end
delta_p = (m2-m1) - (f11 - f21);
p = max([1-max([(f12-f21-delta_p)/(w1+w2),0]),0]);
if p > alfa 
    A = A+1;
elseif p < 1 - alfa
    B = B+1;
else
    C = C+1;
end
alpha_up = max([f12,f22]);
if alpha_up == f12
    alpha_low = max([f11,f21,f22]);
else
    alpha_low = max([f11,f21,f12]);
end
alpha1 = [alpha_low,alpha_up];
d1 = sqrt(((f11-alpha1(1))^2+(f12-alpha1(2))^2)/2);
d2 = sqrt(((f21-alpha1(1))^2+(f22-alpha1(2))^2)/2);
p = d1/(d1+d2);
if p > alfa 
    A = A+1;
elseif p < 1-alfa
    B = B+1;
else
    C = C+1;
end
d3 = max(abs(f11-alpha1(1)),abs(f12-alpha1(2)));
d4 = max(abs(f21-alpha1(1)),abs(f22-alpha1(2)));
p = d3/(d3+d4);
if p > alfa 
    A = A+1;
elseif p < 1 - alfa
    B = B+1;
else
    C = C+1;
end
if f12 <= f21
    p = 1;
elseif (f11<f21&f21<f12&f12<f22)
    p = (f22-f12)/(f22-f21)+((f12-f21)/(f22-f21))*(0.5*(f12-f21)/(f12-f11)+(f21-f11)/(f12-f11));
elseif (f21<=f11&f11<=f12&f12<=f22)
    p = (f22-f12)/(f22-f21)+0.5*((f22-f21)/(f22-f21));
else
    p = 0;
end
pa = p;
pb = 1 - pa;
pab=1-pa-pb;
pp = [pa,pb,pab];
[~,xuhao] = max(pp);
if xuhao == 1
    A = A+1;
elseif xuhao == 2
    B = B+1;
else
    C = C+1;
end
re = [A,B,C];
[~,index] = max(re);
if flag == 1
    if index == 1
        result = [f11 f12];
    elseif index == 2
        result = [f21 f22];
    else
        result = [f11 f21];
    end
else
    if index == 1
        result = [f21 f22];
    elseif index == 2
        result = [f11 f12];
    else
        result = [f11 f21];
    end
end
end    
